package com.suxin.servlet;

import com.suxin.MyHandler;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;
import java.lang.reflect.Constructor;
import java.util.Set;

/**
 * @Classname MyServletContainerInitializer
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2021/1/6 9:34
 * @Created by ASUS
 */
@HandlesTypes(value = {MyHandler.class})
public class MyServletContainerInitializer implements ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        System.out.println("size: " + set.size());
        set.forEach(item -> {
            try {
                Constructor<?> constructor = item.getDeclaredConstructor(null);
                MyHandler myHandler = (MyHandler) constructor.newInstance(null);
                System.out.println(myHandler);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

}